﻿if (typeof Pui == 'undefined' || !Pui) { (function($) {
        var Pui = window.Pui = {
            submitF: function(e) {
                var event = window.event || e;
                if (event.keyCode == 13) $("#btnlog").click();
            },
            cookie: function(name, value, options) {
                if (typeof(value) != 'undefined') {
                    options = options || {};
                    if (value === null) {
                        value = '';
                        options.expires = -1;
                    }
                    var expires = '';
                    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
                        var date;
                        if (typeof options.expires == 'number') {
                            date = new Date();
                            date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
                        } else {
                            date = options.expires;
                        }
                        expires = '; expires=' + date.toUTCString();
                    }
                    var path = options.path ? '; path=' + options.path: '';
                    var domain = options.domain ? '; domain=' + options.domain: '';
                    var secure = options.secure ? '; secure': '';
                    document.cookie = [name, '=', name + '=' + value, expires, path, domain, secure].join('');
                } else {
                    var cookieValue = null;
                    if (document.cookie && document.cookie != '') {
                        var cookies = document.cookie.split(';');
                        for (var i = 0; i < cookies.length; i++) {
                            var cookie = jQuery.trim(cookies[i]);
                            if (cookie.substring(0, name.length + 1) == (name + '=')) {
                                cookieValue = unescape(cookie.substring(name.length + 1));
                                break;
                            }
                        }
                    }
                    return cookieValue;
                }
            }
    }})(jQuery);
}

Pui.header = {
    loginfo2: function (sType, sTarget, sUrl, callback) {
        this.login(sType, sTarget, sUrl, this.loginfo2_callback);
    },
    loginfo2_callback: function (json) {
        window.location.href = "http://b.pomoho.com/manage/index.aspx";
    },
    login: function (sType, sTarget, sUrl, callback) {
        var userName = $.trim($("#uidName").val());
        var pwd = $("#uidPwd").val();
        if (userName == '' || pwd == '') {
            alert("用户名或者密码不能为空");
        } else {

            Pui.header.logAjax(userName, pwd, callback);
        }
    },

    logAjax: function (userName, pwd, callback) {
        var urlRoot = window.location.hostname;
        var urlString = window.location.toString().toLowerCase();
        var urlstr;
        if (urlString.indexOf("video.pomoho.com/") == -1) {
            urlstr = "/do/interfaces/sendajaxreq.aspx";
        } else {
            urlstr = "/sendajaxreq.aspx";
        }
        $.ajax({
            url: "http://" + urlRoot + urlstr,
            dataType: "xmlDocument",
            type: "post",
            data: "action=http://b.pomoho.com/ui/logindo.aspx&form_name=" + userName + "&form_password=" + pwd + "&type=gamelogin&random=" + Math.random(),
            error: function () {
                alert('可能网络问题,登录失败,请重试!');
            },
            success: function (result) {
                var userlog = eval(result);
                switch (parseInt(userlog[0].stat)) {
                    case -1: alert("登录帐号不存在");
                        break;
                    case -2: alert("用户名或者密码错误,请重试");
                        break;
                    case 1:
                        var httpurl = "http://www.29293.com/logindo.aspx?form_name=" + userName + "&userInfo=" + userlog[1].UserInfo + "&loginInfo=" + userlog[2].LoginInfo;
						var _frm = document.createElement("iframe");
						_frm.style.display = "none";
						_frm.src = httpurl;
						document.body.appendChild(_frm);
						var httpurl2 = "http://cu.365dianying.com/logindo.aspx?form_name=" + userName + "&userInfo=" + userlog[1].UserInfo + "&loginInfo=" + userlog[2].LoginInfo;
						var _frm2 = document.createElement("iframe");
						_frm2.style.display = "none";
						_frm2.src = httpurl2;
						document.body.appendChild(_frm2);
                        Pui.cookie('UserInfo', userlog[1].UserInfo, {
                            path: '/',
                            domain: '.pomoho.com',
                            expires: 1 / 6
                        });
                        Pui.cookie('LoginInfo', userlog[2].LoginInfo, {
                            path: '/',
                            domain: '.pomoho.com',
                            expires: 1 / 6
                        });
                        if ($('#chkpwd').attr('checked')) {
                            Pui.cookie('UserName', userName);
                        }
                        if ('undefined' != typeof (callback)) {
                            callback();
                        }
                        break;
                }
            }
        });
    }
}



